package com.shure.surdes.common.result;

import java.io.Serializable;

/**
 * @ClassName Result
 * @Description 结果封住类
 * @Author shure
 * @Date 2023/3/16 17:33
 * @Version 1.0
 **/

public class Result<T> implements Serializable {


    public static <T> R<T> create(int code, String msg, T data) {
        return new R<T>(code, msg, data);
    }

    public static <T> R<T> success(T data) {
        return new R<T>(data);
    }

    public static <T> R success() {
        return R.SUCCESS;
    }

    public static <T> R<T> ok() {
        return success();
    }

    public static <T> R<T> ok(T data) {
        return success(data);
    }

    public static <T> R error() {
        return R.SERVER_ERROR;
    }

    public static <T> R<T> error(String msg) {
        return new R<>(R.SERVER_ERROR.getCode(), msg);
    }

    public static <T> R<T> error(int code, String msg) {
        return new R<>(code, msg);
    }

    public static <T> R<T> error(String msg, T data) {
        return new R<>(R.SERVER_ERROR.getCode(), msg, data);
    }

    public static <T> R<T> error(T data) {
        return new R<>(R.SERVER_ERROR.getCode(), R.SERVER_ERROR.getMsg(), data);
    }

    public static <T> R<T> error(R<T> codeMsg) {
        return codeMsg;
    }

    public static <T> R<T> fail() {
        return error();
    }

    public static <T> R<T> fail(T data) {
        return error(data);
    }
}
